﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using SQLExecute; 

public partial class edit_form_phep : System.Web.UI.Page
{
    public string strMessage=string.Empty;
    DataSet ds;
    

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["username"] != null && Request.Params["id"] != null)
            {
                Init_Combo();
                Get_Data_Nghi_Phep();
                lUsername.Text = Session["username"].ToString();
                lFullName.Text = Session["fullname"].ToString();
            }
        
        }
          
  
        

    }
    protected void Init_Combo()
    {

        cbNghi.Items.Add("Nghỉ buổi sáng");
        cbNghi.Items.Add("Nghỉ buổi chiều");
        cbNghi.Items.Add("Nghỉ nguyên ngày");
        cbNghi.Items.Insert(0, new ListItem("Choose One", "Choose One"));

        cbNghi.SelectedIndex = 0;
        /*
        string sql = "select * from tbl_phongban order by phongban asc";
        ds = SqlHelper.ExecuteDataset(Common.strConnect, CommandType.Text, sql);
        if (ds.Tables[0].Rows.Count > 0)
        {
            cbPhongBan.DataSource = ds;
            cbPhongBan.DataTextField = "phongban";
            cbPhongBan.DataValueField = "id";
            cbPhongBan.DataBind();
            cbPhongBan.Items.Insert(0, new ListItem("Choose One", "Choose One"));
            cbPhongBan.SelectedIndex = 0;
        }*/

        cbLoaiPhep.Items.Add("Phép năm");
        cbLoaiPhep.Items.Add("Phép đặc biệt");
        cbLoaiPhep.Items.Add("Nghỉ không hưởng lương");
        cbLoaiPhep.Items.Add("Nghỉ ốm");

        cbLoaiPhep.Items.Insert(0, new ListItem("Choose One", "Choose One"));
        cbLoaiPhep.SelectedIndex = 0;


    }

    protected void Get_Data_Nghi_Phep()
    {
        int id = Convert.ToInt16(Request.Params["id"].ToString());
        NghiPhep n = new NghiPhep();
        n = n.Get_Info_Nghi_Phep(id);
        //cbPhongBan.SelectedValue = n.MaPhongBan.ToString();
        lPhongBan.Text = Session["tenphongban"].ToString();
        string s1=n.NghiTuNgay.ToShortDateString();
        txtFromDate.Text = Common.Convert_MMDDYYYY_To_DDMMYYY(s1);

        s1 = n.NghiDenNgay.ToShortDateString();         
        txtToDate.Text = Common.Convert_MMDDYYYY_To_DDMMYYY(s1);
       
        
        cbNghi.Text = n.ThoiGianNghi;
        cbLoaiPhep.Text = n.LoaiPhep;
        txtLydo.Text = n.LyDo;

        
    }
    protected void lnkLogout_Click(object sender, EventArgs e)
    {
        FormsAuthentication.SignOut();
        Session.Clear();
        Response.Redirect("login.aspx");
    }
    protected void btnNghiPhepCu_Click(object sender, EventArgs e)
    {
        Response.Redirect("list_nghiphep.aspx");
    }
}
